﻿package org.ilanchong.droidcontroller.socket;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;

public class DroidClient {
	private Socket client = null;
	private OutputStream out = null;

	public DroidClient(String address, int port) throws UnknownHostException,
			IOException {
		client = new Socket(address, port);
	}

	public void setTimeOut(int timeout) throws SocketException {
		client.setSoTimeout(timeout);
	}

	public void sendCommand(String cmd) throws IOException {
		if (client != null) {
			out = client.getOutputStream();
			String data = cmd;
			out.write(data.getBytes());
		}
	}

	public void close() throws IOException {
		if (client != null && !client.isClosed()){
			client.close();
		}
		if (out != null){
			out.close();
		}
	}
}
